package com.example.ui.learn.util;

import java.util.ArrayList;

import com.example.huashangapp.R;
import com.example.ui.learn.util.TypeAdapter.Holder;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DetailAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<Detail> list;
	public DetailAdapter(Context mContext,ArrayList<Detail> list){
		inflater = LayoutInflater.from(mContext);
        this.list=list;
	}
	public ArrayList<Detail> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<Detail> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<Detail>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		Detail cc=list.get(position);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.detail_item, null);
			holder = new Holder();
        	
			holder.textTitle = (TextView) convertView.findViewById(R.id.di_title);
			holder.tvcontent=(TextView) convertView.findViewById(R.id.di_content);
        	convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
		
		
		holder.textTitle.setText(cc.getTitle());
		holder.tvcontent.setText(Html.fromHtml(cc.getContent()));
		
		return convertView;
	}
	
	class Holder{
    	
    	TextView textTitle;
    	TextView tvcontent;
    	
    	
    }
}
